<script type="text/javascript" src="jquery.js"> </script>		
<script type="text/javascript" src="prototype.js"> </script>
<script type="text/javascript" src="JForm.js"></script>
<fieldset>
<!-- checkin by yangjian's id -->
	<legend>创建权限</legend>
	<form id="role_form" action="roleCreate.do">
		<table align="left">
			<tr>
				<th><font>权限名</font></th>
				<td>
					<input type="text" id="actionname" name="actionname">
				</td>
			</tr>
			<tr>
				<th><font>权限代码</font></th>
				<td>
					<input type="text" id="actioncode" name="actioncode">
				</td>
			</tr>
			<tr>
				<th><font>权限级别</font></th>
				<td>
					<select id="roleLevel" class="required" name="roleLevel">
						<%
							List roleLevels = (List) RoleLevelService.$.getRoleLevels();  
							for(int i = 0; i < roleLevels.size(); i++) {
								//Actioncolumn roleLevel = (Actioncolumn) roleLevels.get(i);
						%>
	                   <option><%//= roleLevel.getActioncolumnname() %></option>
						<%
							}
						%>
	               </select>
				</td>
			</tr>
			<tr>	
				<td>
					<input class='button' type="button" value="添加" onclick="if(true || formValidate(this)) {addRole();}">
				</td>
				<td>
					<input class='button' type="button" value="取消">
				</td>
			</tr>
		</table>
	</form>
</fieldset>
<fieldset>
	<legend>权限列表</legend>
	<table  align="left">
		<tr>
			<th>权限名</th>
			<th>权限级别</th>
			<th>操作</th>
		</tr>
	<%
		List roleList = RoleCreateService.$.getRoles(); 
		for(int i = 0, n = roleList.size(); i < n; i++) {
	 		Action role = (Action) roleList.get(i);  
	 %>
		<tr>
			<td><%= role.getActionname()%></td>
			<td><%//= (null == role.getActioncolumn()) ? "暂无" : role.getActioncolumn().getActioncolumnname()%></td>
			<td>删除</td>
		</tr>
	<% 
		}
	%>
	</table>
</fieldset>
<div id="add_Result">
</div>
<script type="text/javascript">
	var JForm = Class.create();       
	Object.extend(JForm.prototype, {           
		validate : function(DOMTREE){
			var userid = $('userid_add').value;
			var uiRegExp = new RegExp("^[a-z]*", "i")
			if(!uiRegExp.test(userid)) {
				alert('userid is invalid');
				return false;
			}
						
			//myRegExp.exec('a'),  return the result array
			
			return true;
	    }
	});

	formValidate = function(DOMTREE) {
		var validator = new JForm();
		return true;
		//return validator.validate(DOMTREE);
	}
	callBack = function(resp) {
		var resText = resp.responseText;
		if(resText.indexOf('UserException:')>-1) {
			//alert('UserException');
			$('right').innerHTML = resText;
		} else {
			$('right').innerHTML = resText;
		}
		var successful = false;
		if(successful) {
			var sp = document.createElement("textArea");
			sp.innerHTML = "success";
			var footerDiv = document.getElementById('copyright');
			footerDiv.appendChild(sp);	
		}
		else {
			var sp = document.createElement("textArea");
			sp.innerHTML = "success";
			var footerDiv = document.getElementById('copyright');
			footerDiv.appendChild(sp);	
		}
	}
	addRole = function() {
		var role_form = document.getElementById('role_form');
		//must add the '/' 
		var url =  "/" + "<%= LocalContants.PROJECT_NAME %>" + "/roleCreate.do";// + person_form.serialize();
		var pars = role_form.serialize();
		var myAjax = new Ajax.Request(url,{method:'post',parameters: pars,onComplete:callBack,evalScripts:true});
	}
</script>

<%@ page import="java.util.*" %>
<%@ page import="com.esms.struts.service.*" %>
<%@ page import="com.esms.bean.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>